import request from "@/utils/request";

// 登录方法
export function login(data) {
  return request({
    url: "/login",
    headers: {
      isToken: false,
      repeatSubmit: false,
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: 'post',
    data
  })
}

// 注册方法
export function register(data) {
  return request({
    url: "/register",
    headers: {
      isToken: false,
    },
    method: "post",
    data: data,
  });
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/resource/detail',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: "/logout",
    method: "post",
  });
}

export function getCodeImg() {
  return request({
    url: "/captchaImage",
    headers: {
      isToken: false,
    },
    method: 'get',
    timeout: 20000
  })
}

// 获取公钥
export function getPubKey() {
  return request<string>(
    {
      url: '/passwordPubKey',
      headers: {
        isToken: false
      },
      method: 'get',
      timeout: 20000
    })
}

// 发送忘记密码短信验证码
export function sendForgetPasswordVerifyCode(data) {
  return request<string>({
    url: '/resource/sendUpdatePasswordVerifyCode',
    headers: {
      isToken: false
    },
    method: 'post',
    data,
  })
}

// 提交忘记密码
export function forgetPasswordReq(data) {
  return request<string>({
    url: '/resource/verifyCodeUpdatePassword',
    headers: {
      isToken: false
    },
    method: 'post',
    data
  })
}

// 获取用户身份集合
export function getIdentityCodeReq(data, headers) {
  return request<string>({
    url: '/identityCode',
    headers: {
      isToken: false,
      ...headers,
    },
    method: 'get',
    params: data
  })
}

// 切换身份登录
export function switchLoginReq(data: {identityCode: string}) {
  return request<string>({
    url: '/switch/login',
    method: 'post',
    data
  })
}

// 获取OA的token
export function getOaTokenReq(data: {code: string}) {
  return request<string>({
    url: '/oauth/getToken',
    method: 'get',
    params: data
  })
}

